package com.xlf.service.base.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xlf.common.core.annotation.Log;
import com.xlf.common.core.enums.BusinessType;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.common.core.util.StringUtils;
import com.xlf.pojo.base.Difficulty;
import com.xlf.pojo.base.Problem;
import com.xlf.service.base.mapper.ProblemMapper;
import com.xlf.service.base.pojo.dto.admin.DifficultyDTO;
import com.xlf.service.base.service.DifficultyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/11/22 21:32
 * @Description: TODO 难度管理
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/admin/difficulty")
public class AdminDifficultyController extends BaseController {

    @Autowired
    DifficultyService difficultyService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('base:admin:difficulty:list')")
    public AjaxResult list(Difficulty difficulty){
        startPage();
        return success(getDataTable(difficultyService.getList(difficulty)));
    }

    @PostMapping("/saveOrUpdate")
    @Log(mode = "难度管理", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('base:admin:difficulty:saveOrUpdate')")
    public AjaxResult saveOrUpdate(@RequestBody Difficulty difficulty){
        return success(difficultyService.saveOrUpdate(difficulty));
    }


    @GetMapping("/query/{id}")
    @PreAuthorize("@ss.hasPermi('base:admin:difficulty:query')")
    public AjaxResult query(@PathVariable(value = "id") String id){
        return success(difficultyService.getById(id));
    }

    @DeleteMapping("/delete")
    @PreAuthorize("@ss.hasPermi('base:admin:difficulty:delete')")
    @Log(mode = "难度管理", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestBody List<String> ids){
        difficultyService.delete(ids);
        return success("删除成功！");
    }

    @PutMapping("/disabled")
    @PreAuthorize("@ss.hasPermi('base:admin:difficulty:disabled')")
    public AjaxResult updateStatus(@RequestBody Difficulty difficulty){
        return success(difficultyService.updateStatus(difficulty));
    }
}
